Skip to content

chore: external merge request from Contributor#36925

Closed
rahulbarwal wants to merge 20 commits intoreleasefrom
external-contri/fix/button-tooltip-in-table_widgetV2
Closed

chore: external merge request from Contributor#36925
rahulbarwal wants to merge 20 commits intoreleasefrom
external-contri/fix/button-tooltip-in-table_widgetV2

Conversation

@rahulbarwal
Copy link
Contributor

@rahulbarwal rahulbarwal commented Oct 17, 2024

Description

Issue: #10278

Original PR: #36865
EE PR: https://github.com/appsmithorg/appsmith-ee/pull/5373

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.All"

🔍 Cypress test results

Caution

If you modify the content in this section, you are likely to disrupt the CI result for your PR.

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11588397189
Commit: 44de49c
Cypress dashboard.
Tags: @tag.All
Spec:


Wed, 30 Oct 2024 09:07:02 UTC

Summary by CodeRabbit

  • New Features

    • Enhanced styling for table widget components, improving layout flexibility and visual feedback.
    • Introduced new styled components for better modularity: RenderOptionWrapper, MenuCategoryWrapper, and TooltipContentWrapper.
    • Improved tooltip functionality for buttons, accommodating text truncation scenarios.
  • Bug Fixes

    • Refined hover states for checkbox components to enhance user experience.
  • Refactor

    • Updated the tooltip logic to better handle button-specific requirements.
    • Adjusted rendering logic in the button component for improved interactivity with tooltips.

skjameela and others added 2 commits October 14, 2024 16:14
@rahulbarwal rahulbarwal self-assigned this Oct 17, 2024
@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Oct 17, 2024
@rahulbarwal rahulbarwal added the ok-to-test Required label for CI label Oct 17, 2024
@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

@github-actions
Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11379477080.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36925.
recreate: .

@github-actions
Copy link

Deploy-Preview-URL: https://ce-36925.dp.appsmith.com

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 22, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes in this pull request primarily involve enhancements to the styling and functionality of table widget components. Modifications include new properties and styled components in TableStyledWrappers.tsx, improvements to tooltip handling in AutoToolTipComponent.tsx, and updates to the button rendering logic in Button.tsx. These adjustments aim to improve the visual presentation, interactivity, and user feedback within the table widget.

Changes

File Change Summary
app/client/src/widgets/TableWidgetV2/component/TableStyledWrappers.tsx - Added new styled components: RenderOptionWrapper, MenuCategoryWrapper, TooltipContentWrapper.
- Updated ActionWrapper with max-width: 100%;.
- Modified CellCheckboxWrapper for borderRadius and hover states.
- Enhanced CellWrapper with conditional styling based on isCellDisabled.
- General refactoring for consistency.
app/client/src/widgets/TableWidgetV2/component/cellComponents/AutoToolTipComponent.tsx - Added isButtonTextTruncated helper function.
- Updated useToolTip to include isButton parameter for button-specific tooltip handling.
- Adjusted event listeners for clarity.
app/client/src/widgets/TableWidgetV2/component/cellComponents/Button.tsx - Imported AutoToolTipComponent and ColumnTypes.
- Updated rendering logic to include tooltip functionality for buttons.

Possibly related PRs

Suggested labels

Enhancement, Widgets Product, UI Building Product, Test, Widgets & Accelerators Pod, High

Suggested reviewers

  • ApekshaBhosale
  • sagar-qa007
  • jacquesikot

🎉 In the realm of tables, where widgets reside,
New styles and tooltips, oh what a ride!
With buttons that sparkle and checkboxes that gleam,
Enhancements abound, like a coder's sweet dream.
So here's to the changes, both big and small,
Together we build, together we stand tall! 🎈


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

@github-actions
Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11456391351.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36925.
recreate: .

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (4)
app/client/src/widgets/TableWidgetV2/component/cellComponents/Button.tsx (1)

Line range hint 46-72: LGTM: Button component enhanced with tooltip.

The Button component now includes an AutoToolTipComponent wrapper, improving user experience. The conditional rendering logic is updated correctly.

Consider extracting the condition props.isCellVisible && props.action.isVisible && props.action.label into a separate variable for better readability:

const shouldRenderButton = props.isCellVisible && props.action.isVisible && props.action.label;

return (
  <ActionWrapper
    disabled={!!props.isDisabled}
    onClick={(e) => {
      e.stopPropagation();
    }}
  >
    {shouldRenderButton ? (
      <AutoToolTipComponent
        columnType={ColumnTypes.BUTTON}
        title={props.action.label}
      >
        {/* ... */}
      </AutoToolTipComponent>
    ) 
    : null}
  </ActionWrapper>
);
app/client/src/widgets/TableWidgetV2/component/TableStyledWrappers.tsx (3)

Line range hint 516-524: LGTM. Add test for disabled cell state.

The addition of isCellDisabled property with conditional styling enhances the visual indication of disabled cells. Consider adding a test case to verify the correct rendering of disabled cells.

Would you like me to generate a test case for the disabled cell state?


Line range hint 844-860: LGTM. Consider responsive design.

The new RenderOptionWrapper component improves option rendering with consistent layout. Consider implementing responsive design for smaller screen sizes to ensure usability across devices.

Consider adding media queries for smaller screens:

export const RenderOptionWrapper = styled.div<{ selected: boolean }>`
  // ... existing styles ...
+ @media (max-width: 768px) {
+   width: 100%;
+   .title {
+     width: calc(100% - 30px);
+   }
+   .type {
+     left: auto;
+     right: 10px;
+   }
+ }
`;

Line range hint 872-875: LGTM. Enhance accessibility.

The new TooltipContentWrapper component effectively manages tooltip content display. Consider adding ARIA attributes to improve accessibility for screen readers.

Enhance accessibility by adding ARIA attributes:

export const TooltipContentWrapper = styled.div<{ width?: number }>`
  word-break: break-all;
  max-width: ${(props) => props.width}px;
+ role: tooltip;
+ aria-live: polite;
`;
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4f55f52 and dd9b0b4.

📒 Files selected for processing (3)
  • app/client/src/widgets/TableWidgetV2/component/TableStyledWrappers.tsx (1 hunks)
  • app/client/src/widgets/TableWidgetV2/component/cellComponents/AutoToolTipComponent.tsx (2 hunks)
  • app/client/src/widgets/TableWidgetV2/component/cellComponents/Button.tsx (3 hunks)
🧰 Additional context used
🔇 Additional comments (6)
app/client/src/widgets/TableWidgetV2/component/cellComponents/Button.tsx (1)

5-10: LGTM: New imports added.

The new imports for ColumnTypes and AutoToolTipComponent are correctly added and align with the changes in the Button component.

app/client/src/widgets/TableWidgetV2/component/TableStyledWrappers.tsx (2)

Line range hint 604-624: LGTM. Ensure consistent borderRadius usage.

The addition of borderRadius property and refined hover states enhance the checkbox's visual feedback and customization. Verify that the borderRadius prop is consistently applied across the application for uniform styling.

#!/bin/bash
# Description: Check for consistent borderRadius usage
# Test: Search for borderRadius prop in styled components
rg -p 'borderRadius.*\${.*}' app/client/src/widgets

476-476: LGTM. Verify layout impact.

The addition of max-width: 100%; to ActionWrapper is appropriate for full-width expansion. Ensure this doesn't adversely affect the layout of action buttons in various table configurations.

✅ Verification successful

Layout impact verified. No issues found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential layout issues caused by the max-width change
# Test: Search for ActionWrapper usage in table-related components
rg -p 'ActionWrapper' app/client/src/widgets/TableWidgetV2

Length of output: 267


Script:

#!/bin/bash
# Description: Re-attempt to check for ActionWrapper usage in table-related components
# Test: Search for ActionWrapper usage
rg 'ActionWrapper' app/client/src/widgets/TableWidgetV2

Length of output: 503

app/client/src/widgets/TableWidgetV2/component/cellComponents/AutoToolTipComponent.tsx (3)

47-51: Addition of isButton parameter in useToolTip function

The updated function signature accommodates button-specific tooltip behavior.


95-95: Update useEffect dependency array

Including isButton ensures the effect runs when isButton changes.


186-190: Handle button columns in AutoToolTipComponent

The additional condition correctly handles tooltips for button columns.

Comment on lines +39 to +45
function isButtonTextTruncated(element: HTMLElement) {
const spanElement = element.querySelector("span");
const offsetWidth = spanElement?.offsetWidth ?? 0;
const scrollWidth = spanElement?.scrollWidth ?? 0;

return scrollWidth > offsetWidth;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Check for null spanElement before accessing properties

If spanElement is null, accessing its properties will cause an error.

Apply this diff to handle the null case:

function isButtonTextTruncated(element: HTMLElement) {
  const spanElement = element.querySelector("span");
+ if (!spanElement) return false;
  const offsetWidth = spanElement.offsetWidth;
  const scrollWidth = spanElement.scrollWidth;
  return scrollWidth > offsetWidth;
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function isButtonTextTruncated(element: HTMLElement) {
const spanElement = element.querySelector("span");
const offsetWidth = spanElement?.offsetWidth ?? 0;
const scrollWidth = spanElement?.scrollWidth ?? 0;
return scrollWidth > offsetWidth;
}
function isButtonTextTruncated(element: HTMLElement) {
const spanElement = element.querySelector("span");
if (!spanElement) return false;
const offsetWidth = spanElement.offsetWidth;
const scrollWidth = spanElement.scrollWidth;
return scrollWidth > offsetWidth;
}

@github-actions
Copy link

Deploy-Preview-URL: https://ce-36925.dp.appsmith.com

@rahulbarwal rahulbarwal marked this pull request as draft October 23, 2024 08:51
@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

@github-actions
Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11476436884.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36925.
recreate: .

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
app/client/src/widgets/TableWidgetV2/component/cellComponents/Button.tsx (1)

44-46: Consider using a more specific event type.

The event handler could benefit from explicit typing.

-  const stopPropagation = (e: React.MouseEvent<HTMLDivElement>) => {
+  const stopPropagation = (e: MouseEvent<HTMLDivElement, MouseEvent>) => {
app/client/src/widgets/TableWidgetV2/component/cellComponents/AutoToolTipComponent.tsx (1)

55-98: Consider reviewing the useEffect dependency array.

Including ref in the dependency array may not be necessary since refs typically don't change between renders. Also, ensure that including children and isButton is required to avoid unnecessary re-renders.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between dd9b0b4 and 39d624e.

📒 Files selected for processing (2)
  • app/client/src/widgets/TableWidgetV2/component/cellComponents/AutoToolTipComponent.tsx (2 hunks)
  • app/client/src/widgets/TableWidgetV2/component/cellComponents/Button.tsx (2 hunks)
🧰 Additional context used
🔇 Additional comments (6)
app/client/src/widgets/TableWidgetV2/component/cellComponents/Button.tsx (3)

5-8: LGTM! Clean import organization.


10-10: LGTM! Appropriate tooltip component import.


49-68: 🛠️ Refactor suggestion

Consider optimizing the click handler with useCallback.

The inline onClick handler in ActionWrapper could cause unnecessary re-renders.

+ const handleStopPropagation = useCallback((e: MouseEvent<HTMLDivElement, MouseEvent>) => {
+   e.stopPropagation();
+ }, []);

  return (
-    <ActionWrapper disabled={!!props.isDisabled} onClick={stopPropagation}>
+    <ActionWrapper disabled={!!props.isDisabled} onClick={handleStopPropagation}>

Additionally, let's verify the tooltip implementation consistency.

✅ Verification successful

The previous pattern might have failed due to syntax. Let's try these alternative approaches to gather the necessary information about the tooltip implementation and event handling patterns.


I found the AutoToolTipComponent file. Let's examine its implementation and check for similar event handler patterns in related components to make a more informed decision about the optimization suggestion.


The useCallback optimization suggestion is valid and aligns with existing patterns

The codebase shows consistent use of useCallback for stopPropagation handlers, as seen in SelectCell.tsx. The optimization would align with the existing patterns and prevent unnecessary re-renders.

  • Found similar optimized implementation in SelectCell.tsx: const onClick = useCallback((e) => e.stopPropagation(), [])
  • AutoToolTipComponent implementation confirms it's a complex component with state management, making render optimization important

The original suggestion to optimize the click handler remains valid:

+ const handleStopPropagation = useCallback((e: MouseEvent<HTMLDivElement, MouseEvent>) => {
+   e.stopPropagation();
+ }, []);

  return (
-    <ActionWrapper disabled={!!props.isDisabled} onClick={stopPropagation}>
+    <ActionWrapper disabled={!!props.isDisabled} onClick={handleStopPropagation}>
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for consistent AutoToolTipComponent usage in table components
ast-grep --pattern 'AutoToolTipComponent columnType={$_} title={$_}'

Length of output: 70


Script:

#!/bin/bash
# Let's try a different approach to find AutoToolTipComponent usage
rg -U "AutoToolTipComponent.*columnType.*title" -A 2 -B 2

# Also check for the component definition
rg "export.*AutoToolTipComponent"

# Let's also verify if stopPropagation is used consistently
rg "stopPropagation.*onClick" -A 2 -B 2

Length of output: 261


Script:

#!/bin/bash
# Let's check the implementation of AutoToolTipComponent
cat app/client/src/widgets/TableWidgetV2/component/cellComponents/AutoToolTipComponent.tsx

# Let's also check for similar event handler patterns in the same directory
rg "const.*useCallback.*stopPropagation" app/client/src/widgets/TableWidgetV2/component/cellComponents/

Length of output: 6629

app/client/src/widgets/TableWidgetV2/component/cellComponents/AutoToolTipComponent.tsx (3)

39-45: Null safety handled correctly in isButtonTextTruncated.

The use of optional chaining and default values ensures that accessing properties of spanElement will not cause errors if it's null. Good job addressing the previous concern.


47-51: useToolTip function updated appropriately with isButton parameter.

The addition of the optional isButton parameter is correctly implemented, enhancing the function's flexibility.


184-193: Conditional rendering for button tooltips implemented correctly.

The logic for handling ColumnTypes.BUTTON with the useToolTip function is clear and effective.

@github-actions
Copy link

Deploy-Preview-URL: https://ce-36925.dp.appsmith.com

@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

@github-actions
Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11512821324.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36925.
recreate: .

@github-actions
Copy link

Deploy-Preview-URL: https://ce-36925.dp.appsmith.com

@rahulbarwal rahulbarwal added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Oct 25, 2024
@rahulbarwal
Copy link
Contributor Author

Closing as original PR is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants